import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
// import { OptionalAuthGuard } from '@wwjCommon/security/guards/optional-auth.guard';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { MemberCashOutAccountService } from '../../services/api/member-cash-out-account.service';

/**
 * CashOutAccountController
 * 对应 PHP: CashOutAccount Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('member')
@Controller('api/member')
@UseGuards(ApiCheckTokenGuard)
export class CashOutAccountController {
  constructor(
    private readonly memberCashOutAccountService: MemberCashOutAccountService,
  ) {}

  /**
   * lists
   * 路由: GET cashout_account
   * PHP路由: Route::get('cashout_account', 'member.CashOutAccount/lists')
   */
  @Get('cashout_account')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'lists' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.memberCashOutAccountService.getPage(data);
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * info
   * 路由: GET cashout_account/:account_id
   * PHP路由: Route::get('cashout_account/:account_id', 'member.CashOutAccount/info')
   */
  @Get('cashout_account/:account_id')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'info' })
  async info(@Param('account_id') account_id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: info

      return await this.memberCashOutAccountService.getInfo(account_id);
    } catch (error) {
      throw new BusinessException('info操作失败', error);
    }
  }

  /**
   * firstInfo
   * 路由: GET cashout_account/firstinfo
   * PHP路由: Route::get('cashout_account/firstinfo', 'member.CashOutAccount/firstInfo')
   */
  @Get('cashout_account/firstinfo')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'firstInfo' })
  async firstInfo(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: firstInfo

      return await this.memberCashOutAccountService.getFirstInfo(data);
    } catch (error) {
      throw new BusinessException('firstInfo操作失败', error);
    }
  }

  /**
   * add
   * 路由: POST cashout_account
   * PHP路由: Route::post('cashout_account', 'member.CashOutAccount/add')
   */
  @Post('cashout_account')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'add' })
  async add(@Body() data: AddDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: add

      return await this.memberCashOutAccountService.add(data);
    } catch (error) {
      throw new BusinessException('add操作失败', error);
    }
  }

  /**
   * edit
   * 路由: PUT cashout_account/:account_id
   * PHP路由: Route::put('cashout_account/:account_id', 'member.CashOutAccount/edit')
   */
  @Put('cashout_account/:account_id')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'edit' })
  async edit(
    @Param('account_id') account_id: string,
    @Body() data: EditDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: edit

      return await this.memberCashOutAccountService.edit(account_id, data);
    } catch (error) {
      throw new BusinessException('edit操作失败', error);
    }
  }

  /**
   * del
   * 路由: DELETE cashout_account/:account_id
   * PHP路由: Route::delete('cashout_account/:account_id', 'member.CashOutAccount/del')
   */
  @Delete('cashout_account/:account_id')
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: 'del' })
  async del(@Param('account_id') account_id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: del

      return await this.memberCashOutAccountService.del(account_id);
    } catch (error) {
      throw new BusinessException('del操作失败', error);
    }
  }
}
